class Solution {
public:
    vector<int> stk;
    vector<vector<int>> ans;
    void dfs(vector<vector<int>>& graph,int depth,int maxDepth)
    {
        if(depth==maxDepth)
        {
            ans.push_back(stk);
            return ;
        }
        for(auto& y:graph[depth])
        {
            stk.push_back(y);
            dfs(graph,y,maxDepth);
            stk.pop_back();
        }
    }
    //graph 的第 i 个数组中的单元都表示有向图中 i 号节点所能到达的下一些结点
    vector<vector<int>> allPathsSourceTarget(vector<vector<int>>& graph) {
        if(graph.size()==0)
            return ans;
        stk.push_back(0);//因为题目要从0开始
        dfs(graph,0,graph.size()-1);
        return ans;
    }
};